home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / KEYBOARD.SWG / 0016_Keyboard SCAN Codes.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  2KB  |  60 lines

  1. {
  2. ROBERT ROTHENBURG
  3.  
  4. >I have created a Menu Bar, Now I think key #77 is left and key #77 is
  5. >assigned to "M" or one of them. But anyway so when someone pushes the
  6. >"M" key the menu bar moves. So how can I stop this, I only want it to
  7. >use the arrow keys and a few letters but not "M".
  8.  
  9. You guessed it: USE BIOS CALLS!
  10. }
  11.  
  12. Program ShowCodes; {* This Program will output the keyboard
  13.                    {* scan codes.  Use the Function "ScanCode"
  14.                    {* in your Program once you know the codes
  15.                    {* For each keypress *}
  16. Uses
  17.   Crt, Dos;
  18.  
  19. Function Byte2Hex(numb : Byte): String;       { Converts Byte to hex String }
  20. Const
  21.   HexChars : Array[0..15] of Char = '0123456789ABCDEF';
  22. begin
  23.   Byte2Hex[0] := #2;
  24.   Byte2Hex[1] := HexChars[numb shr  4];
  25.   Byte2Hex[2] := HexChars[numb and 15];
  26. end; { Byte2Hex }
  27.  
  28. Function Numb2Hex(numb : Word): String;        { Converts Word to hex String.}
  29. begin
  30.   Numb2Hex := Byte2Hex(hi(numb)) + Byte2Hex(lo(numb));
  31. end; { Numb2Hex }
  32.  
  33. Function ScanCode : Word;
  34. Var
  35.   reg : Registers;    {* You need the Dos Unit For this! *}
  36. begin
  37.   reg.AH := $10;      {* This should WAIT For a keystroke.  If
  38.                       {* you'd like to POLL For a keystroke and
  39.                       {* have your Program do other stuff While
  40.                       {* "waiting" For a key-stroke change to
  41.                       {* reg.AH:=$11 instead... *}
  42.   intr($16, reg);
  43.   ScanCode := reg.AX  {* The high-Byte is the "scan code" *}
  44. end;                  {* The low-Byte is the ASCII Character *}
  45.  
  46. begin
  47.   Repeat
  48.     Writeln(Numb2Hex(ScanCode) : 6)
  49.   Until False;        {* You'll have to reboot after running this <g>*}
  50. end.
  51.  
  52. {
  53. I "think" the arrow-key scan codes are:
  54.  
  55.    $4800 = Up Arrow
  56.    $5000 = Down Arrow
  57.    $4B00 = Left Arrow
  58.    $4D00 = Right Arrow
  59. }
  60.